<?php
include 'secure/core.php';
if(isset($_POST['submit'])){
if($earnings->requestPendingPayment($_POST)){
header( 'Location: payment.php?msg=1' ) ;	
} else {
header( 'Location: payment.php?msg=2' ) ;
}
}
include 'user_header.php';
include 'left.php'; 
$payment_threshold = $settings->getPaymentThreshold();
?>
		<div id="right">
		<div class="section">
		<?php if($_GET['msg'] == '1') { ?>
			 <div class="message green"><span><b>Success</b>: Your payment request was successfully added.</span></div>
			 <?php } ?>
			 <?php if($_GET['msg'] == '1') { ?>
			 <div class="message red"><span><b>Error</b>: There was a problem submitting your payment request.</span></div>
			 <?php } ?>
				<div class="box">
					<div class="title">
						Request Payment
						<span class="hide"></span>
					</div>
					<div class="content">
					<form action="">
						<div class="row">
						<?php if($earnings->getPendingPayment($_SESSION['userid']) > $payment_threshold) { ?>
						You have earned $<?php echo $earnings->getPendingPayment($_SESSION['userid']); ?> which means you can now request payment
						<?php } else { ?>
						You currently have earned $<?php echo $earnings->getPendingPayment($_SESSION['userid']); ?> while using our site. It wont be long until you can request a payment now.
						<?php } ?>
						</div>
					</form>
				</div></div>
				<div class="box">
					<div class="title">
						Payment Request Form</strong>
						<span class="hide"></span>
					</div>
					<div class="content">
					<?php
					$payment_details = $earnings->getUserDetailsWithPendingAmount($_SESSION['userid']);
					$pending_amount = $payment_details['amount'] - $payment_details['payout_amount'];
					$pending_amount = $earnings->getPendingPayment($_SESSION['userid']);
					if($pending_amount < 0){
			                $pending_amount = 0;
		                        }
		                        ?>
		                        <?php 
	                                if(!$earnings->isPaymentAlreadyRequested($_SESSION['userid'])){
	                                if($pending_amount > $payment_threshold){?>
					 <form action="payment.php" method="post">
							<div class="row">
								<label>Request Amount</label>
							<div class="right"><input type="text" value="" name="amount" /></div>
							</div>
							<div class="row">
								<label>Payment Email</label>
							<div class="right"><input type="text" value="" name="email" /></div>
							</div>
							<div class="row">
								<div class="right">
									<button type="submit" name="submit" class="green"><span>Request</span></button>
								</div>
							</div>
						</form>
						 <?php }else{?> 
                                               You must earn atleast $10 before you can request a payment
                                                 <?php }}else{?>
                                               You have already requested a payment this month
                                              <?php } ?>			
					</div>
				</div>
				
				</div>
			</div>
		</div>

<?php include 'footer.php'; ?>